package edu.zqu.collegeField.project.controller;


import cn.hutool.core.util.StrUtil;
import edu.zqu.collegeField.project.po.FieldApplication;
import edu.zqu.collegeField.project.po.FieldApplicationStatus;
import edu.zqu.collegeField.project.service.FieldApplicationStatusService;
import edu.zqu.collegeField.project.vo.FieldApplicationStatusVo;
import edu.zqu.collegeField.project.vo.FieldApplicationVo;
import edu.zqu.common.result.ZQUResult;
import edu.zqu.common.status.HttpStatus;
import edu.zqu.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

/**
 * <p>
 * 场地申请用途字典 前端控制器
 * </p>
 *
 * @author 廖森
 * @since 2020-06-28
 */
@RestController
@RequestMapping("/api")
@Api(tags = "场地申请用途字典")
public class FieldApplicationStatusController {
    @Autowired
    private FieldApplicationStatusService fieldApplicationStatusService;

    @ApiOperation(value = "获取场地申请用途字典列表")
    @GetMapping(value = "/fieldApplicationStatuses")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "collegeId", value = "学校id", paramType = "query", required = true),
            @ApiImplicitParam(name = "name", value = "场地申请用途名称", paramType = "query", required = false),
            @ApiImplicitParam(name = "englishName", value = "英文名", paramType = "query", required = false)
    })
    public ZQUResult get(BigInteger collegeId,
                         String name,
                         String englishName
    ) {
        List<FieldApplicationStatusVo> fieldApplicationStatusVoList = fieldApplicationStatusService.get(
                collegeId, StrUtil.trimToNull(name), StrUtil.trimToNull(englishName));
        if (StringUtils.isNotEmpty(fieldApplicationStatusVoList)) {
            return new ZQUResult(HttpStatus.SUCCESS, "请求成功", fieldApplicationStatusVoList);
        } else return new ZQUResult(HttpStatus.NO_CONTENT, "请求失败", null);
    }

    @ApiOperation(value = "获取场地申请用途字典信息", response = FieldApplicationStatusVo.class)
    @GetMapping(value = "/fieldApplicationStatus/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "场地申请用途字典id", paramType = "path", required = true)
    })
    public ZQUResult getById(@PathVariable BigInteger id) {
        FieldApplicationStatusVo fieldApplicationStatusVo = fieldApplicationStatusService.getById(id);
        if (StringUtils.isNotNull(fieldApplicationStatusVo)) {
            return new ZQUResult(HttpStatus.SUCCESS, "请求成功", fieldApplicationStatusVo);
        }
        return new ZQUResult(HttpStatus.NO_CONTENT, "请求失败", null);
    }

    @ApiOperation(value = "添加")
    @PostMapping(value = "/fieldApplicationStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "FieldApplicationStatus", name = "FieldApplicationStatus", value = "场地申请用途字典对象", paramType = "query", required = true)
    })
    public ZQUResult add(@RequestBody FieldApplicationStatus fieldApplicationStatus) {
        int rs = fieldApplicationStatusService.add(fieldApplicationStatus);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "添加成功", null);
        }
        return new ZQUResult(HttpStatus.ERROR, "添加失败", null);
    }

    @ApiOperation(value = "更新")
    @PutMapping(value = "/fieldApplicationStatus")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "FieldApplicationStatus", name = "FieldApplicationStatus", value = "场地申请用途字典对象", paramType = "query", required = true)
    })
    public ZQUResult update(@RequestBody FieldApplicationStatus fieldApplicationStatus) {
        int rs = fieldApplicationStatusService.update(fieldApplicationStatus);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "修改成功", null);
        }
        return new ZQUResult(HttpStatus.ERROR, "修改失败", null);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/fieldApplicationStatus/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "场地申请用途字典id", paramType = "path", required = true),
            @ApiImplicitParam(name = "byWho", value = "用户id", paramType = "query", required = true)
    })
    public ZQUResult delete(@PathVariable Integer id, BigInteger byWho) {
        int rs = fieldApplicationStatusService.delete(id, byWho);
        if (rs >= 1) {
            return new ZQUResult(HttpStatus.SUCCESS, "删除成功", null);
        }
        return new ZQUResult(HttpStatus.ERROR, "删除失败", null);
    }

}

